package cn.zhaoyan.bean;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class PageBean {
    //当前页
    private int pageNum =1;
    //每页显示的数据10
    private int pageSize =5;

    //总条数select count(1)from ? 100
    private int totalCounts;

    //总页码(totalCounts%pageSize)== 0 ? totalCounts/pageSize : totalCounts/pageSize+1
    private int totalPages;
    //要显示的数据内容
    private List<Customer> list;
    //起始页 (pageNum-1)*pageSize     limit 0,10
    private  int startIndex;

    //上一页 pageNum-1
    private  int beforePage;
    //下一页 pageNum+1
    private int nextPage;

    //分页栏前五后四 大于十页
    private  int pageBar[];



    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCounts() {
        return totalCounts;
    }

    public void setTotalCounts(int totalCounts) {
        this.totalCounts = totalCounts;
    }


    public int getTotalPages() {
        return totalPages= (totalCounts%pageSize) == 0 ? totalCounts/pageSize : totalCounts/pageSize + 1;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public List<Customer> getList() {
        return list;
    }

    public void setList(List<Customer> list) {
        this.list = list;
    }


    public int getStartIndex() {

        return startIndex = (pageNum-1)*pageSize;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getBeforePage() {
        beforePage= this.pageNum-1;
        if (beforePage<=0){
            this.beforePage=1;
        }
        return beforePage;
    }

    public void setBeforePage(int beforePage) {
        this.beforePage = beforePage;
    }

    public int getNextPage() {
        nextPage= this.pageNum+1;
        if (nextPage>=totalPages){
            this.nextPage=totalPages;
        }
        return this.nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public int[] getPageBar() {
        //首页
        int beginPage;
        //尾页
        int engPage;
        if (totalPages <= 10){
            beginPage=1;
            engPage=totalPages;
        }else {
            beginPage = this.pageNum - 5;
            engPage = this.pageNum + 4;

            if (beginPage <= 0) {
                beginPage = 1;
                engPage = beginPage + 9;

            }
            if (engPage >= totalPages) {
                beginPage = totalPages - 9;
                engPage = totalPages;
            }
        }
        this.pageBar= new int[engPage-beginPage + 1];
        int index = 0;
        for (int i= beginPage; i<= engPage; i++){
            pageBar[index++]=i;
        }
        System.out.println(Arrays.toString(pageBar));
        return this.pageBar;
    }

    public void setPageBar(int[] pageBar) {
        this.pageBar = pageBar;
    }

    public PageBean() {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totalCounts = totalCounts;
        this.totalPages = totalPages;
        this.list = list;
        this.startIndex = startIndex;
        this.beforePage = beforePage;
        this.nextPage = nextPage;
        this.pageBar = pageBar;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", totalCounts=" + totalCounts +
                ", totalPages=" + totalPages +
                ", list=" + list +
                ", startIndex=" + startIndex +
                ", beforePage=" + beforePage +
                ", nextPage=" + nextPage +
                ", pageBar=" + Arrays.toString(pageBar) +
                '}';
    }
}
